Como ya he hecho en las entregas 1 y 2, voy a poner el foco en la facultad de Políticas y Sociología, así como en realizar comparaciones con facultades del Campus de Somosaguas
---
title: "Alumnado UCM Somosaguas"
author: "Jorge Blanco"
date: "`r Sys.Date()`"
output:
flexdashboard::flex_dashboard:
source_code: embed
logo: logos/man.png
favicon: logos/ucm_favicon.png
social: [ "twitter", "facebook", "menu" ]
navbar:
- { title: "Proyecto Aula Innova - R", href: "https://ucm.es/aula_innova", align: left }
orientation: rows
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readr)
library(dplyr)
library(ggplot2)
library(DT)
library(plotly)
df <- read_delim("datos_tratados.csv", delim = ";")
df$CURSO <- factor(df$CURSO)
df$CENTRO <- factor(df$CENTRO)
# Agrupamos los datos por curso
grouped_data_somosaguas <- df %>%
filter((CENTRO == "POLITICAS_Y_SOCIOLOGIA" | CENTRO == "PSICOLOGIA" | CENTRO == "ECONOMICAS_Y_EMPRESARIALES")) %>%
group_by(CURSO) %>%
summarise(across(where(is.numeric), sum))
# Agrupamos los datos por curso
grouped_data_politicas <- df %>%
filter(CENTRO == "POLITICAS_Y_SOCIOLOGIA") %>%
group_by(CURSO) %>%
summarise(across(where(is.numeric), sum))
df_4_M <- select(grouped_data_somosaguas,CURSO,TOTAL_MUJERES)
df_4_H <- select(grouped_data_somosaguas,CURSO,TOTAL_HOMBRES)
colnames(df_4_M)[2] <-"TOTAL"
colnames(df_4_H)[2] <-"TOTAL"
df_4_M$GÉNERO <- rep('Mujer', times = nrow(df_4_M))
df_4_H$GÉNERO <- rep('Hombre', times = nrow(df_4_H))
df_5 <- bind_rows(df_4_M,df_4_H)
```
# Página 1
## Fila 1 {data-height=200}
### Explicación de mi dashboard
Como ya he hecho en las entregas 1 y 2, voy a poner el foco en la facultad de Políticas y Sociología, así como en realizar comparaciones con facultades del Campus de Somosaguas
1. __Página 1__
Tabla y gráfico con el número de matriculados hombres y mujeres, así como los porcentajes relativos, de algunas de las facultades emplazadas en el Campus de Somosaguas (Políticas y Sociología, Económicas y Psicología).
2. __Página 2:__
Gráfico interactivo con los estudiantes de las facultades.
## Fila 2 {data-height=800}
### Tabla de datos {data-width=400}
```{r}
# Crear una tabla interactiva con DT
tabla_interactiva <- datatable(filter(df,(CENTRO == "POLITICAS_Y_SOCIOLOGIA" | CENTRO == "PSICOLOGIA" | CENTRO == "ECONOMICAS_Y_EMPRESARIALES")), options = list(pageLength = 25))
tabla_interactiva
```
### Total de alumnos por curso {data-width=600}
```{r fig.width=10, fig.height=5}
df %>% filter(CENTRO == "POLITICAS_Y_SOCIOLOGIA" | CENTRO == "PSICOLOGIA" | CENTRO == "ECONOMICAS_Y_EMPRESARIALES") %>%
ggplot(aes(x = CURSO, y = TOTAL, fill = CENTRO)) +
geom_col() +
labs(title = "U.C.M. Campus Somosaguas", x = "Curso", y = "Total de alumnos/as",
) +
theme(axis.text.x = element_text(angle = 30, vjust = 1, hjust = 1, size = 8))
```
# Página 2
## Fila 1
### Componente dinámico con ggplot + plotly {data-width=500}
```{r}
g1 <-ggplot(df_5, aes(x = CURSO, y = TOTAL, color = GÉNERO, size = TOTAL)) +
geom_point() +
labs(title = "Total de Alumnos Facultades Seleccionadas Somosaguas",
subtitle = "Políticas y Sociología, Económicas y Psicología",
x = "CURSO",
y = "Total",
caption = "SIDI") +
theme(axis.text.x = element_text(angle = 30, vjust = 1, hjust = 1, size = 8))
g2 <- ggplotly(g1)
g2
```
### Componente estático con ggplot {data-width=500}
```{R}
df_3 <- filter(df, CENTRO == "POLITICAS_Y_SOCIOLOGIA")
df_3$CURSO <- factor(df_3$CURSO)
df_3$CENTRO <- factor(df_3$CENTRO)
df_4_M <- select(df_3,CURSO,CENTRO,TOTAL_MUJERES)
df_4_H <- select(df_3,CURSO,CENTRO,TOTAL_HOMBRES)
colnames(df_4_M)[3] <-"TOTAL"
colnames(df_4_H)[3] <-"TOTAL"
df_4_M$GENERO <- rep('Mujer', times = nrow(df_4_M))
df_4_H$GENERO <- rep('Hombre', times = nrow(df_4_H))
# Ahora uno las tablas de Hombre y Mujer
df_5 <- bind_rows(df_4_M,df_4_H)
g1 <-ggplot(df_5) +
geom_col(aes(y=TOTAL, x = CURSO, color = GENERO)) +
labs(title = "Mujeres y hombres que estudian en la Facultad de Políticas y Sociología",
subtitle = "Gráficos de barras",
x = " ",
y = "Número de estudiantes \n ",
caption = "Fuente: SIDI, UCM."
) +
theme(axis.text.x = element_text(size = 10, angle = 30, vjust = 1, hjust = 1),
#arriba(top), izquierda (left), derecha (right)
legend.position = "top")
g1
```